﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Admin.Controls
{
    public partial class EditRecruitment : System.Web.UI.UserControl
    {
        DataTable dt;
        public string name;
        public string title;
        public string summary;
        public string description;
        public int id;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                id = Convert.ToInt32(Request.QueryString["id"]);
                dt = DAL.DCollector.DBCollector.Instance.StoredSelectAllTableWhereID("tbl_TuyenDung", "TuyenDung_ID", id.ToString());
                name = dt.Rows[0]["TuyenDung_TieuDe"].ToString();
                title = dt.Rows[0]["TuyenDung_Title"].ToString();
                summary = dt.Rows[0]["TuyenDung_Summary"].ToString();
                description = dt.Rows[0]["TuyenDung_Description"].ToString();
                txtName.Text = name;
                txtTitle.Text = title;
                txtSummary.Text = summary;
                txtDescription.Text = description;

            }
            catch (Exception)
            {
                Response.Redirect("/Admin/error.htm");
            }
        }

        protected void btnUpdateSlide_Click(object sender, EventArgs e)
        {
            if (name != "")
            {
                DAL.DHelpers.Column[] cl = new DAL.DHelpers.Column[4];
                cl[0] = new DAL.DHelpers.Column("TuyenDung_TieuDe", txtName.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                cl[1] = new DAL.DHelpers.Column("TuyenDung_Title", txtTitle.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                cl[2] = new DAL.DHelpers.Column("TuyenDung_Summary", txtSummary.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                cl[3] = new DAL.DHelpers.Column("TuyenDung_Description", txtDescription.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                string[] colWhere = new string[1];
                colWhere[0] = "TuyenDung_ID";

                object[] colValue = new object[1];
                colValue[0] = id;

                DAL.DCollector.DBCollector.Instance.Update("tbl_TuyenDung", cl, colWhere, colValue);
                Response.Redirect("/Admin/Index.aspx?panel=3&sub=16");
            }
            else
            {
                Response.Write("<script>alert('Không thể để tên trống");
            }
        }
    }
}